<?php
/**
 * Created by PhpStorm.
 * User: wuchao
 * Date: 2020/5/19
 * Time: 15:36
 */
namespace app\api\controller\v1\home;

use app\middleware\ApiAuth;
use think\Request;
use think\facade\Validate;
use think\response\Json;
use think\validate\ValidateRule;
use app\api\model\OrderModel;
class Order
{
    protected $middleware = [ApiAuth::class];

    /**
     * @desc 添加地址
     * @return Json
     */
    public function NewOrder(Request $request){
        $input['goodsData'] = $request->post('goodsData');//商品数据
        $input['uid'] = $request->post('uid');//用户ID
        $input['addressID'] = $request->post('addressID');//用户地址ID
        $input['total'] = $request->post('total');//商品总价
        $input['admin_id'] = $request->post('admin_id');//运营商ID
        $input['remark'] = $request->post('remark');//备注
        // 参数校验
        $validate = Validate::rule([
            'goodsData' => ValidateRule::isRequire(),
            'uid' => ValidateRule::isRequire(),
            'addressID' => ValidateRule::isRequire(),
            'total' => ValidateRule::isRequire(),
            'admin_id' => ValidateRule::isRequire(),
        ]);
        if (!$validate->check($input)) {
            return jsonFail($validate->getError());
        }
        //逻辑处理
        return OrderModel::NewOrder($input);
    }
}